// person.js

// 区间生成随机数
const rand = require("../js/functions.js").rand
// 中央集中型（纺缍型）区间生成随机数
const mrand = require("../js/functions.js").mrand


///////////////////////////////////////////////////////////
//
// Person 类
//
///////////////////////////////////////////////////////////

const Person = {
	id : 0,
	skillname: ['剑术', '骑术', '弓术', '坚壁', '威压', '激励', '混乱', '挑唆'],
	skillenum: {jianshu: 0, qishu: 1, gongshu: 2, jianbi: 3, weiya: 4, jili: 5, hunluan: 6, tiaoshuo: 7},
	createNew : function(sex){
		const p = {
			_proto: Person,

			id: Person.id,
			personName: getPersonName(sex),
			sex: sex || 0,    // 0, male, 1,female,

			// 武力，智力，魅力。 以普通人平均水平为30，各项能力有效值在20-60之间，魅力在20-100之间。魅力除加宝物外不可变
			wise: mrand(20, 80), 
			force: mrand(20, 80), 
			glame: sex == 1 ? rand(90, 99) : mrand(20, 99), 
			wiseExp: 0, forceExp: 0,
			
			// 剑术，骑术，弓术，坚壁，威压，激励，混乱，挑唆
			skill: [
				mrand(0, 4), mrand(0, 4), mrand(0, 4), mrand(0, 4),
				mrand(0, 4), mrand(0, 4), mrand(0, 4), mrand(0, 4)
			],
			skillName: function(n) { return Person.skillname[n]},
			skillLevel: function(n) { return level(this.skill[n])},

			// 武器，+force; 书本，+wise; 马匹，免俘; 配饰，+glame
			weapon: 0, book: 0, horse: 0, ruby: 0,  

			status: 1,  		// 1:正常，0:死亡
			rank: 0, 			// 衔
			grade: 0, 			// 爵

		}
		p.lead = function(){
			let b = Math.max(this.force, this.wise)
			let s = Math.min(this.force, this.wise)
			return Math.ceil(b * 0.5 + s * 0.3 + this.glame * 0.2)
		}
		p.poli = function(){
			return Math.ceil(this.wise * 0.6 + this.force * 0.2 + this.glame * 0.2)
		}
		Person.id ++
		return p 
	}
}

///////////////////////////////////////////////////////////
//
// rank 类
//
///////////////////////////////////////////////////////////

const Rank = {
	rankTypes: [],
	createNew: function(){
		const p = {
			_proto: Rank,
			id: "",
			name: "",
			addKnowledge: 0,
			addForce: 0,
		}
		p.isGeneral = function(){ return Rank.isGeneral(p) }
		return p
	},

	isGeneral: function(p){
		return p.id.substr(1, 1) == 'W' ? true : false
	},

}


///////////////////////////////////////////////////////////
//
// specil 类
//
///////////////////////////////////////////////////////////

const Special = {
	id: 0,
	createNew: function(){
		const p = {
			_proto: Frank,
			id: Special.id,
			name: "",
			adder: 0
		}
		return p
	}
}

// ////////////////////////////////////////////////////////
module.exports = {
	Person, Rank, Special
}




// 生成姓名
const getPersonName = function(sex){
	let surname = '赵孙李周吴郑王冯陈卫沈韩杨朱秦许何吕施张孔曹严金魏陶姜谢章苏潘葛范彭鲁马苗花方任袁柳鲍史唐费薛雷贺汤殷罗毕郝安常乐于皮齐伍余顾孟黄和穆萧'
				+ '尹姚邵汪祁毛狄米伏成戴宋庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路江童颜郭梅盛林钟徐邱高夏蔡田胡凌霍万管卢丁邓包左石崔龚程邢陆'
	let dbsurname = '上官东郭司马诸葛夏侯公孙太史欧阳慕容赫连淳于长孙仲孙宇文完颜司徒司空令孤乐正百里司寇'
	let malename = '智信仁勇严义忠龙虎熊鹏豹云飞宇羽超权耀光宗祖煦阳洋柳和同言永昌辉道明胜轩昀盛强伟玮宁松宏泓洪刚钢晋朋友有双清青宜平俊朗嘉怡涛锐学恭'
	let malemidname = '伯伟尚嘉浩天大发祥闻知尊典训正直集材梁礼义为贤度谦恭有道光齐家先孝友之国尚文章珧兆学问通经济功名奏天堂祖训欣永振百世受其昌力子' + malename
	let femalename = '雪兰月玥霜冰纱莎雨婷秀丽茹玉如若丝娜云芸美芙荷娟鹃雅倩蓉湘枫瑾萱璇依琦晶婧静琪欣琳晴颖芳妍媛彤馨香凌绫诗文郁悠娇娆洁梦雯露莲'
	let femalemidname = '小晓筱月云丽芳子紫兰雪茹玉如梦春秋晴芸美欣' + malemidname + femalename
	let nm = ''
	if(Math.random() > 0.96){ // 小概率复姓
		let n = dbsurname.length / 2
		let s = rand(0, n)
		nm += dbsurname[s * 2] + dbsurname[s * 2 + 1]
	}else{
		nm += surname[rand(0, surname.length)]
	}

	if(!sex){
		// male
		if(Math.random() > 0.3) { 
			nm += malemidname[rand(0, malemidname.length)] 
		}
		nm += malename[rand(0, malename.length)]
	}else{
		// female
		if(Math.random() > 0.3) { 
			nm += femalemidname[rand(0, femalemidname.length)] 
		}
		nm += femalename[rand(0, femalename.length)]
	}

	return nm;
}


